<template>
    <el-dialog :visible.sync="isShow" width="800px" title="操作">
        <el-row style="margin-top: 10px">
            <el-form ref="form" :model="form" :rules="rules" label-position="top">
                <el-row style="display: flex;flex-direction: row;flex-wrap: wrap;">
                    <el-col style="margin-left: 20px" :span="item.width?item.width:5" v-for="(item, index) in fieldFormList" :key="index">
                        <el-form-item style="width: 100%;" :label="item.showName" :prop="item.key" v-if="item.formType=='Switch'">
                          <el-switch
                              v-model="form[item.key]"
                              :active-value="true"
                              :inactive-value="false"
                              active-color="#13ce66"
                              inactive-color="#ff4949"
                              />
                        </el-form-item>
                        <el-form-item :label="item.showName" :prop="item.key" v-else-if="item.formType=='Textarea'">
                          <el-input v-model="form[item.key]" placeholder="请输入" type='textarea'/>
                        </el-form-item>
                        <el-form-item :label="item.showName" :prop="item.key" v-else-if="item.formType=='RichText'">
                          <Editor v-model="form[item.key]" :minHeight="600" />
                        </el-form-item>
                        <el-form-item :label="item.showName" :prop="item.key" v-else-if="item.formType=='DatePicker'">
                          <el-date-picker
                            v-model="form[item.key]"
                            :type="item.type"
                            placeholder="选择日期">
                          </el-date-picker>
                        </el-form-item>
                        <el-form-item :label="item.showName" :prop="item.key" v-else-if="item.formType=='Upload'">
                          <single-upload :form="item" :fileUrl="form[item.relatedModel]?form[item.relatedModel]['url']:form[item.key]" @handleFileSuccessForOne="handleFileSuccessForOne"></single-upload>
                        </el-form-item>
                        <el-form-item :label="item.showName" :prop="item.key" v-else-if="item.formType=='SingleSelectDialog'">
                          <div style="display: flex;flex-direction: row;align-items: center;justify-content: space-between;
                          border: #ddd 1px solid;border-radius: 5px;height: 35px;line-height: 35px;padding: 0 10px;"
                          @click="singleSelectAction(item)">
                            <div v-if="form[item.relatedModel] || form[item.key]" style="color: #333;">{{form[item.relatedModel]?form[item.relatedModel][item.relatedKey]:form[item.key]}}</div>
                            <div v-else style="color: #ccc;">请选择</div>
                            <i class="el-icon-search" style="color: #bbb;"></i>
                          </div>
                        </el-form-item>
                        <el-form-item :label="item.showName" :prop="item.key" v-else-if="item.formType=='Option'">
                          <el-select v-model="form[item.key]" placeholder="请选择" clearable>
                            <el-option v-for="item in dictOptions[item.key]" :key="item.value" :label="item.label" :value="item.value"></el-option>
                          </el-select>
                        </el-form-item>
                        <el-form-item :label="item.showName" :prop="item.key" v-else>
                          <el-input v-model="form[item.key]" placeholder="请输入"  />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div style="margin-top: 30px;margin-right: 20px;width: 100%;display: flex;flex-direction: row;justify-content: flex-end;">
                <el-button @click="confirm" type="primary">确定</el-button>
                <el-button @click="close" type="info">取消</el-button>
            </div>
        </el-row>
        <errorDialog ref="errorDialog" :errorList="errorList"></errorDialog>
    </el-dialog>
</template>
    
  <script>
    import { operateActionPost } from '@/api/interface/operate.js'
    import errorDialog from '@/views/interface/form/errorDialog'
    export default {
      components: { errorDialog },
      data() {
        return {
          isShow: false,
          form: {},
          operate: {},
          errorList: [],
          fieldFormList: [],
          rules: {},
          rows: []
        }
      },
      created(){
        // this.findOpenshopList()
      },
      methods:{
        show(val){
          this.rows = val
          this.isShow = true
          
        },
        close(){
            this.isShow = false
        },
        confirm(){
          console.log('this.operate', this.operate)
          this.form.obj_ids = this.rows
          operateActionPost(this.$route.meta.formModel.url + this.operate.key + 'Action/', this.form).then((res) => {
            if(res.data.code == 10000){
              this.$message({
                message: '操作成功',
                type: 'success'
              })
              this.close()
              this.$emit('refreshItemList')
            }else if(res.data.code == 10001){
              console.log('errorList', res.data.data)
              this.close()
              this.errorList = res.data.data
              this.$refs.errorDialog.show()
            }
          })
        },
      }
    }
    </script>
    
    <style lang="scss" scoped>
  
    </style>
    